package com.datawin.taotaocheche.ui.actviity.user;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.jakewharton.rxbinding.view.RxView;

import java.text.DecimalFormat;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import butterknife.Bind;
import com.datawin.taotaocheche.R;
import com.datawin.taotaocheche.base.BaseActivity;
import com.datawin.taotaocheche.bean.UserInfo;
import com.datawin.taotaocheche.event.NetErrorEvent;
import com.datawin.taotaocheche.ui.actviity.user.biz.DrawBackBiz;
import com.datawin.taotaocheche.ui.actviity.user.component.DaggerDrawBackComponent;
import com.datawin.taotaocheche.ui.actviity.user.contract.DrawBackContract;
import com.datawin.taotaocheche.ui.actviity.user.module.DrawBackModule;
import com.datawin.taotaocheche.ui.actviity.user.presenter.DrawBackPresenter;
import rx.functions.Action1;

/**
 * Created by admin on 2017/12/2.
 */

public class DrawBackAct extends BaseActivity implements DrawBackContract.View {


    @Inject
    DrawBackPresenter presenter;
    @Inject
    DrawBackBiz biz;
    @Bind(R.id.draw_back_money)
    TextView money;
    @Bind(R.id.draw_back_input)
    EditText input;
    @Bind(R.id.draw_back_submit)
    TextView submit;

    DecimalFormat df = new DecimalFormat("0.00");

    @Override
    protected void setRoot() {
        setTitleBar("#FFFFFFFF");
        setContentView(R.layout.activity_draw_back);
        // 设置启动Activity时不自动弹出软键盘
        getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    }

    @Override
    protected void setup() {
        setStateText();
        setToolBar("申请退款", "");
        DaggerDrawBackComponent.builder().drawBackModule(new DrawBackModule(this)).build().inject(this);
        presenter.setBiz(biz);
    }


    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        presenter.getUserInfo();
        RxView.clicks(submit)
                .compose(this.<Void>bindToLifecycle())
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        presenter.darwBack();
                    }
                });

    }


    @Override
    public void onNetErrorEvent(NetErrorEvent event) {
        super.onNetErrorEvent(event);
    }

    @Override
    protected void onNetError(NetErrorEvent event) {

    }
    /***
     * Stop location service
     */
    @Override
    protected void onStop() {

        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        biz.onDestory();

    }

    @Override
    public void upDateUI(UserInfo userInfo) {
        money.setText(df.format(userInfo.getAmount()));
    }
}
